import { Component } from '@angular/core';
import { NavController,ItemSliding } from 'ionic-angular';//少了一个组件
import { Task } from '../task';
import { InputTaskPage } from '../../pages/input-task/input-task';

@Component({
  selector: 'page-tasklist',
  templateUrl: 'tasklist.html'
})
export class TaskListpage {
  tasks: Array<Task> = [];

  constructor(public navCtrl: NavController) {

  }
  ionViewDidLoad(){
    this.tasks = [
      {title:'牛奶', status: 'open'},
      {title: '鸡蛋', status: 'open'},
      {title:'果汁', status: 'open'},
      {title: '煎饼', status: 'open'},
      
    ]

  }
  addTask(){
    let addModal= this.madalCtrl.create(InputTaskPage);
    let theNewTask: string = prompt("新任务");
    if(theNewTask !==''){
      this.tasks.push({title:theNewTask,status: 'open'});
    }
    
  }
  markAsDone(slidingItem: ItemSliding,task: Task){
    task.status = 'done';
    slidingItem.close();

  }
  removeTask(slidingItem: ItemSliding,task: Task){
    task.status = 'removed';
    let index = this.tasks.indexOf(task);
    if(index > -1){
      this.tasks.splice(index, 1);

  }


  }
}
